#include <bits/stdc++.h>
using namespace std;
int fib(int n)
{
    if(n == 0)
        return 0;
    else if(n == 1)
        return 1;
    else
        return fib(n-1)+fib(n-2);
}
int main(int argc,char **argv) {
    int num;
    cin>>num;
    int i;
    for(i=0;i<num;i++)
    {
        if(fib(i)>num)
            break;
    }
    cout<<min(abs(fib(i-1)-num),abs(fib(i)-num))<<endl;
}